const targetColorObj = {
  '1': '#1f89cc',
  '2': '#195bc8',
  '3': '#28a986',
  '4': '#b467ca',
}
const methodColorObj = {
  '模型': {
    bgColor: '#effbff',
    color: '#2897ff',
  },
  '端到端': {
    bgColor: '#fff2e1',
    color: '#fd9100',
  },
  '规则': {
    bgColor: '#d8f9f0',
    color: '#28a986',
  },
}
const getGraphChart = (list) => {
  let graphChart = {}
  if (list && list.length) {
    graphChart = {
      id: 'none',
      type: "tops",
      shape: 'tree-node',
      width: 0,
      height: 0,
      label: '',
      x: 0,
      y: 0,
      isShow: false,
      isActived: true,
      isExpand: false,
      children: []
    }
    list.forEach((item, index) => {
      let graphItem = {
        id: `${index+1}`,
        parentIds: ['none'],
        type: "deviceType",
        shape: 'tree-node',
        label: item.data.deviceTypeName,
        width: 40,
        height: 280,
        x: 0,
        y: 0 + index * 330,
        isShow: true,
        isActived: false,
        isExpand: false,
        children: []
      }
      if (item.children && item.children.length) {
        item.children.forEach((item1, index1) => {
          let graphItem1 = {
            id: `${index+1}-${index1+1}`,
            parentIds: ['none', `${index+1}`],
            type: "subDeviceType",
            shape: 'tree-node',
            label: item1.data.deviceTypeName,
            width: 100 ,
            height: 40,
            x: 100,
            y: 0 + index * 330 + index1 * 90,
            isShow: false,
            isActived: false,
            isExpand: false,
            children: []
          }
          if (item1.children && item1.children.length) {
            item1.children.forEach((item2, index2) => {
              let graphItem2 = {
                id: `${index+1}-${index1+1}-${index2+1}`,
                parentIds: ['none', `${index+1}`, `${index+1}-${index1+1}`],
                type: "keyComponents",
                shape: 'tree-node',
                label: item2.data.deviceTypeName,
                data: item2,
                width: 140,
                height: 40 ,
                x: 250,
                y: 0 + index * 330 + index2 * 90,
                isShow: false,
                isActived: false,
                isExpand: false,
                children: []
              }
              if (item2.children && item2.children.length) {
                item2.children.forEach((item3, index3) => {
                  let graphItem3 = {
                    id: `${index+1}-${index1+1}-${index2+1}-${index3+1}`,
                    parentIds: ['none', `${index+1}`, `${index+1}-${index1+1}`, `${index+1}-${index1+1}-${index2+1}`],
                    type: "content",
                    shape: 'target-node',
                    label: '',
                    data: item3,
                    targetColor: targetColorObj[item3.data.libraryType],
                    methodBgColor: methodColorObj['端到端'].bgColor,
                    methodColor: methodColorObj['端到端'].color,
                    width: 280,
                    height: 136,
                    x: 460,
                    y: 0 + index * 330 + index3 * 190,
                    isShow: false,
                    isActived: false,
                    isExpand: false,
                    children: []
                  }
                  graphItem2.children.push(graphItem3)
                })
              }
              graphItem1.children.push(graphItem2)
            })
          }
          graphItem.children.push(graphItem1)
        })
      }
      graphChart.children.push(graphItem)
    })
  }
  return graphChart
}

export {
  getGraphChart
}